package com.boolib.animate.framework.service.advice;

import com.alibaba.fastjson.JSON;
import com.boolib.animate.commons.Consts;
import com.boolib.animate.commons.base.BaseCurdService;
import com.boolib.animate.framework.entity.AnimateChapterComment;
import com.boolib.animate.framework.service.base.impl.BaseAnimateChapterCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @author nier
 * @create 2020-02-29 11:20
 */
@Slf4j
@Service
public class AnimateChapterCommentService   {
    @Autowired
    private BaseAnimateChapterCommentService baseAnimateChapterCommentService;

    public PageInfo<AnimateChapterComment> queryAll(Long id,Integer page,Integer size){

        Example  example = new Example(AnimateChapterComment.class);
        example.createCriteria().andEqualTo("workId",id).andEqualTo("isDel", Consts.ENABLE).andEqualTo("showStatus",Consts.ENABLE);
        example.orderBy("createTime").desc();
        PageHelper.startPage(page,size);
        return new PageInfo<>(baseAnimateChapterCommentService.queryByExample(example));
    }

    public AnimateChapterComment  saveAll(AnimateChapterComment animateChapterComment) {
        final AnimateChapterComment animateChapterComment1 = baseAnimateChapterCommentService.saveSelective(animateChapterComment);
        return animateChapterComment1;
    }

    public AnimateChapterComment increment(Long id) {
        final AnimateChapterComment animateChapterComment = baseAnimateChapterCommentService.queryByIdThrow(id);
        log.info(JSON.toJSONString(animateChapterComment));
        animateChapterComment.setPraiseCount(animateChapterComment.getPraiseCount()+1);
        log.info(JSON.toJSONString(animateChapterComment.getPraiseCount()));
        final AnimateChapterComment animateChapterComment1 = baseAnimateChapterCommentService.updateByIdNoQuery(animateChapterComment);
        log.info(JSON.toJSONString(animateChapterComment));
        log.info(JSON.toJSONString(animateChapterComment1));
        return animateChapterComment1;
    }
}
